package org.example.seata.common.rabbitmq.config;

import org.example.seata.common.rabbitmq.constant.ExchangeQueueRoutingKey;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hzq
 * @date 2021/11/29 17:32
 */
@Configuration
public class RabbitBindingConfiguration {

    /**
     * 订单延时直接队列绑定订单延时直接交换器
     *
     * @param orderDelayDirectQueue    订单延时直接队列
     * @param orderDelayDirectExchange 订单延时直接交换器
     * @return 绑定
     */
    @Bean
    public Binding orderDelayDirectQueueBindingOrderDelayDirectExchange(Queue orderDelayDirectQueue, DirectExchange orderDelayDirectExchange) {
        return BindingBuilder.bind(orderDelayDirectQueue).to(orderDelayDirectExchange).with(ExchangeQueueRoutingKey.ORDER_DELAY_DIRECT_ROUTING_KEY);
    }

    /**
     * 延时队列的死信队列绑定
     * 订单直接队列绑定订单直接交换器
     *
     * @param orderDirectQueue    订单队列
     * @param orderDirectExchange 订单交换器
     * @return 绑定
     */
    @Bean
    public Binding orderDirectQueueBindingOrderDirectExchange(Queue orderDirectQueue, DirectExchange orderDirectExchange) {
        return BindingBuilder.bind(orderDirectQueue).to(orderDirectExchange).with(ExchangeQueueRoutingKey.ORDER_DIRECT_ROUTING_KEY);
    }

    /**
     * @param orderPayDirectQueue 订单支付队列
     * @param orderDirectExchange 订单交换器
     * @return 绑定
     */
    @Bean
    public Binding orderPayDirectQueueBindingOrderDirectExchange(Queue orderPayDirectQueue, DirectExchange orderDirectExchange) {
        return BindingBuilder.bind(orderPayDirectQueue).to(orderDirectExchange).with(ExchangeQueueRoutingKey.ORDER_PAY_DIRECT_ROUTING_KEY);
    }

}
